package cn.madis.ymcc.mq;

import cn.madis.ymcc.domain.MediaFile;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class MediaProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 消息发送者
     * @param mediaFile
     * @return
     */
    public Boolean SendMediaMessage(MediaFile mediaFile){
        Message<MediaFile> build = MessageBuilder.withPayload(mediaFile).build();
        SendResult sendResult = rocketMQTemplate.syncSend("topic-media:tags-media", build);
        SendStatus sendStatus = sendResult.getSendStatus();
        if (sendStatus == SendStatus.SEND_OK){
            return true;
        }
        return false;


    }
}
